package com.deyuanyun.pic.pipe.service.impl;

import com.deyuanyun.pic.common.dto.BasicDataByFind;
import com.deyuanyun.pic.common.dto.DTOResult;
import com.deyuanyun.pic.common.exception.ExceptionCode;
import com.deyuanyun.pic.common.tool.JXL;
import com.deyuanyun.pic.pipe.mapper.dao.CrossDao;
import com.deyuanyun.pic.pipe.service.CrossService;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * 
 * @ClassName ClosureServiceImpl
 * @Description 管道基础数据 ->套管service实现
 * @author 荣华兴
 * @date 2015年8月31日
 */
@Service
public class CrossServiceImpl implements CrossService {

	@Resource
	private CrossDao crossDao;
	/**
		* @Description: 根据条件查询
		* @Author: 荣华兴
		* @Create Date: 2015年8月31日
		* @参数：@param bData，对象中包含：管道id、管段id、起始里程、终点里程
		* @Return:DTOResult
	 */
	@Override
	public Page<HashMap<String, Object>> findByCondition(BasicDataByFind bData) {
		Page<HashMap<String, Object>> list = new Page<HashMap<String, Object>>();
		Page<HashMap<String, Object>> list2 = new Page<HashMap<String, Object>>();
		
		list= crossDao.findByCondition(bData);
		for (int i=0;i<list.size();i++){
			HashMap map=list.get(i);
			
			map.put("CASINGTYPE", CodeUtil.getName((String) map.get("CASINGTYPE")));
			map.put("ANTISEPTICMATERIAL", CodeUtil.getName((String) map.get("ANTISEPTICMATERIAL")));
			map.put("FILLMATERIAL", CodeUtil.getName((String) map.get("FILLMATERIAL")));
			map.put("SEALTYPE", CodeUtil.getName((String) map.get("SEALTYPE")));
			list2.add(map);
		}
		list2.setTotal(list.getTotal());
		list2.setPageNum(list.getPageNum());
		list2.setPageSize(list.getPageSize());
		return  list2;
		
	}
		/**
		* @Description: 根据传入Id，查询对应Id的详细数据
		* @Author: 荣华兴
		* @Create Date: 2015年8月31日
		* @参数：@param id
		* @参数：@return
		* @Return:DTOResult
	 */
	@Override
	public DTOResult findById(String id) {
		
		List list=null;
		
		try {
			list= crossDao.findById(id);
			
			} catch (SQLException ex) {
				
			ex.printStackTrace();
		}
		return new DTOResult(ExceptionCode.SUCCESS.getCode(), ExceptionCode.SUCCESS.getLabel(), list);
	}
		/**
		* @Description: 根据页面传入的值，查询导出值
		* @Author: 荣华兴
		* @Create Date: 2015年8月31日
		* @参数：@param bData，对象中包含：管道id、管段id、起始里程、终点里程
		* @Return:List<List<String[]>> 套管导出列表
	 */
	@Override
	public List<List<String[]>> excelExport(BasicDataByFind bData) {
		
			
			
			List<List<String[]>> result=new ArrayList<List<String[]>>();
			ArrayList<LinkedHashMap<String, Object>> list = new ArrayList<LinkedHashMap<String, Object>>();
			ArrayList<LinkedHashMap<String, Object>>	list2 =new ArrayList<LinkedHashMap<String, Object>>();
			
				//将数据取出放入list中
			list= crossDao.excelExport(bData);
			for(int i=0;i<list.size();i++){
				LinkedHashMap<String, Object> map=list.get(i);
				map.put("CASINGTYPE", CodeUtil.getName((String) map.get("CASINGTYPE")));
				map.put("ANTISEPTICMATERIAL", CodeUtil.getName((String) map.get("ANTISEPTICMATERIAL")));
				map.put("FILLMATERIAL", CodeUtil.getName((String) map.get("FILLMATERIAL")));
				map.put("SEALTYPE", CodeUtil.getName((String) map.get("SEALTYPE")));
				list2.add(map);
			}
				if(list2.size()==0){
					list=null;
				}
				result.add(JXL.toList(list2, "yyyy-MM-dd"));
				return result;
		}
		


}
